Shader "TideShader/2_漫反射_兰伯特光照模型"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _Diffuse("Diffuse",Color) = (1,1,1,1)
    }
    SubShader
    {
        Tags
        {
            "LightMode" = "ForwardBase"
            "Queue" = "Geometry"
            "RenderType"="Opaque"
        }

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"
            #include "Lighting.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float3 normal:NORMAL;
            };

            struct v2f
            {
                float3 normal:TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _Diffuse;

            //兰伯特光照公式
            half3 LambertLight(half3 n, half3 l)
            {
                return max(0, dot(n, l));
            }

            v2f vert(appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.normal = UnityObjectToWorldNormal(v.normal);
                return o;
            }

            fixed4 frag(v2f i) : SV_Target
            {
                float3 worldNormal = normalize(i.normal);
                float3 worldLightDir = normalize(_WorldSpaceLightPos0);
                float4 lightColor = _LightColor0;
                float3 diffuse = LambertLight(worldNormal, worldLightDir);
                diffuse = diffuse * lightColor * _Diffuse;

                return diffuse.xyzx;
            }
            ENDCG
        }
    }
}